import axios from 'axios'
// Cookie相关方法
//设置cookie
export function setCookie(c_name, value, expiredays) {
  var exdate = new Date()
  exdate.setDate(exdate.getDate() + expiredays)
  document.cookie = c_name + "=" + escape(value) +
    ((expiredays == null) ? "" : ";path=/LiveVideoServer;expires=" + exdate.toGMTString())
}
//获取cookie
export function getCookie(cname) {
  var arr = document.cookie.match(new RegExp("(^| )" + cname + "=([^;]*)(;|$)"));
  if (arr != null) return unescape(arr[2]);
  return null;
}
//清除cookie
export function clearCookie(name) {
  setCookie(name, "", -1);
}

//深度复制
export function deepCopy(source) {
  if (typeof source == 'object') {
    return JSON.parse(JSON.stringify(source))
  } else {
    throw Error('请传对象类型的数据');
  }
}

//判断是不是PC浏览器
export function isPC() {
  var userAgentInfo = navigator.userAgent;
  var Agents = ["Android", "iPhone",
    "SymbianOS", "Windows Phone",
    "iPad", "iPod"
  ];
  var flag = true;
  for (var v = 0; v < Agents.length; v++) {
    if (userAgentInfo.indexOf(Agents[v]) > 0) {
      flag = false;
      break;
    }
  }
  return flag;
}

//判断手机号码是否合法
export function IsPhone(phone) {
  var phoneExp = new RegExp(/^1\d{10}$/); // 电话正则
  return phoneExp.test(phone);
}